package com.xs.util;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

@Data
@SuppressWarnings({"rawtypes", "unchecked"})
public class PageInfoDto<T> {
    private Long allCount;
    private Integer pageSize;
    private Integer pageTotal;
    private Integer pageCurrent;
    private List<T> dataList;
    private Object info;

    public PageInfoDto() {
    }

    public PageInfoDto(Long allCount, Integer pageSize, Integer pageTotal, Integer pageCurrent, List<T> dataList,
                       Object info) {
        this.allCount = allCount;
        this.pageSize = pageSize;
        this.pageTotal = pageTotal;
        this.pageCurrent = pageCurrent;
        this.dataList = dataList;
        this.info = info;
    }

    public static PageInfoDto<?> of(PageInfo<?> pageInfo) {

        PageInfoDto pageInfoDto = new PageInfoDto<>();
        pageInfoDto.setAllCount(pageInfo.getTotal());
        pageInfoDto.setPageCurrent(pageInfo.getPageNum());
        pageInfoDto.setPageSize(pageInfo.getPageSize());
        pageInfoDto.setPageTotal(pageInfo.getPages());
        pageInfoDto.setDataList(pageInfo.getList());
        return pageInfoDto;
    }

    public static PageInfoDto<?> of(PageInfo<?> pageInfo, Object info) {
        PageInfoDto pageInfoDto = new PageInfoDto<>();
        pageInfoDto.setAllCount(pageInfo.getTotal());
        pageInfoDto.setPageCurrent(pageInfo.getPageNum());
        pageInfoDto.setPageSize(pageInfo.getPageSize());
        pageInfoDto.setPageTotal(pageInfo.getPages());
        pageInfoDto.setDataList(pageInfo.getList());
        pageInfoDto.setInfo(info);
        return pageInfoDto;
    }
}